import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:yuellyfactory/views/purchase/PurchaseMaterial.dart';

import '../components/NoScrollbarBehavior.dart';
import '../util/ColorUtil.dart';
import '../util/ViewUtil.dart';
import '../util/XNumberTextInputFormatter.dart';
import 'package:animated_tree_view/animated_tree_view.dart' as treeview;

class Test extends StatefulWidget {
  const Test({super.key});

  @override
  State<Test> createState() => _TestState();
}

class _TestState extends State<Test> {

  treeview.TreeViewController? _controller;
  final totalKey = GlobalKey<ShadFormState>();
  var currentSelect="";
  final dialogKey = GlobalKey<ShadFormState>();
  int currentType=0;

  final sampleTree = treeview.TreeNode.root()
    ..addAll([
      treeview.TreeNode(key: "泳池机",data: 0,)..add(treeview.TreeNode(key: "系列1A",data: 0)),
      treeview.TreeNode(key: "冷水机",data: 0)
        ..addAll([
          treeview.TreeNode(key: "系统2C",data: 0),
          treeview.TreeNode(key: "系统2D",data: 0),
          treeview.TreeNode(key: "系统2E",data: 0)
            ..addAll([
              treeview.TreeNode(key: "机型1A2C",data: 0)
                ..addAll([
                  treeview.TreeNode(key: "热泵",data: 1),
                  treeview.TreeNode(key: "压缩机",data: 1),
                  treeview.TreeNode(key: "箱体钣金",data: 1),
                ]),
            ]),
        ]),
      treeview.TreeNode(key: "0D",data: 0),
      treeview.TreeNode(key: "0E",data: 0),

    ]);
  @override
  Widget build(BuildContext context) {
    final theme = ShadTheme.of(context);
    return Container(
      child: DecoratedBox(
        decoration: BoxDecoration(
          borderRadius: theme.radius,
          border: Border.all(
            color: theme.colorScheme.border,
          ),
        ),
        child: ClipRRect(
          borderRadius: theme.radius,
          child: ShadResizablePanelGroup(
            children: [
              ShadResizablePanel(

                defaultSize: .2,
                minSize: .1,
                maxSize: .5,
                child:

                Card(
                  color: Colors.white,
                  child:  treeview.TreeView.simple(
                      showRootNode: false,
                      focusToNewNode: false,
                      expansionIndicatorBuilder: (context, node) {
                        return treeview.ChevronIndicator.rightDown(
                          tree: node,
                          alignment: Alignment.centerRight,
                          color: Colors.grey[700],
                        );
                      },
                      indentation: const treeview.Indentation(

                          style: treeview.IndentStyle.roundJoint),
                      onItemTap: (item) {
                        print("Item tapped: ${item.key}");
                        currentSelect=item.key;
                        currentType=item.data;
                        setState(() {
                        });
                      },
                      onTreeReady: (controller) {
                        _controller = controller;
                      },
                      builder: (context, node) =>  Container(
                        decoration: BoxDecoration(
                          color: currentSelect==node.key ? Colors.blue.withOpacity(0.1) : null,
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: ListTile(

                          title: Text("${node.key}"),
                        ),
                      ),
                      tree: sampleTree),
                ),
              ),
              ShadResizablePanel(

                defaultSize: .8,
                child:

                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Card( color: Colors.white,
                      child: Padding(
                        padding: const EdgeInsets.all(5.0),
                        child: Row(
                          children: [

                          ],
                        ),
                      ),
                    ),

                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
